package me.wangqu.weiyouqu.web.rest.business.service;

import me.wangqu.weiyouqu.web.rest.business.dao.WithDrawDao;
import me.wangqu.weiyouqu.web.rest.business.model.WithdrawAccount;
import me.wangqu.weiyouqu.web.rest.business.model.WithdrawModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by joln on 2016/6/25.
 */
@Service
public class WithDrawService {
    private final Logger log = LoggerFactory.getLogger(WithDrawService.class);
    @Autowired
    private WithDrawDao withDrawDao;

    /**
     * 获取帐户余额及支付宝信息(微信提现后期实现) - 用于提现流程
     *
     * @param login
     * @return
     */
    public WithdrawAccount getSelfCashAccount(String login) {
        try {
            return withDrawDao.getSelfCashAccount(login);
        } catch (Exception e) {
            log.error("获取账户余额及支付宝信息失败", e.getMessage());
        }
        return null;
    }

    /**
     * 获取提现列表
     *
     * @param login
     * @param pageable
     * @return
     */
    public List<WithdrawModel> getSelfWithdraws(String login, Pageable pageable) {
        try {
            return withDrawDao.getSelfWithdraws(login, pageable);
        } catch (Exception e) {
            log.error("获取提现列表失败", e.getMessage());
        }
        return null;
    }

    /**
     * 判断支付宝是否设置
     *
     * @param login
     * @return
     */
    public boolean isSelfRealName(String login) {
        try {
            return withDrawDao.isSelfRealName(login);
        } catch (Exception e) {
            log.error("支付宝已经设置真实姓名", e.getMessage());
        }
        return false;
    }

    /**
     * 帐户信息设置
     *
     * @param model
     * @param login
     * @return
     */
    public boolean setSelfCashAccount(WithdrawModel model, String login) {
        try {
            return withDrawDao.setSelfCashAccount(model, login);
        } catch (Exception e) {
            log.error("帐户设置失败", e.getMessage());
        }
        return false;
    }

    /**
     * 提现操作
     * @param model
     * @param login
     * @return
     */
    public boolean postSelfWithdraw(WithdrawModel model, String login) {
        try {
            return withDrawDao.postSelfWithdraw(model, login);
        } catch (Exception e) {
            log.error("提现失败", e.getMessage());
        }
        return false;
    }

}
